package countlatch

import "sync"

type Countdownlatch struct {
	 c chan int
	counter int
	lock sync.Mutex
}

func(c *Countdownlatch) Count()  {
	c.lock.Lock()
	c.counter--
	if c.counter==0 {
		c.c<-1
	}
	c.lock.Unlock()
}
func(c *Countdownlatch) Wait()  {
	 <-c.c
}
func GetInstance(counter int) *Countdownlatch {
	c := &Countdownlatch{}
	c.counter=counter
	c.c=make(chan int, 1)
	return  c
}